<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of notification
 *
 * @author Andi
 */
include_once 'database.php';
class notification extends database {
    //put your code here
    function  __construct() {
        $this->connect();
    }

    function showNotifID($userName,$notifBody){
        $query = "SELECT * FROM notification WHERE user_name = '$userName' AND notif_body = '$notifBody'";
        $result = mysql_query($query);
        $row = mysql_fetch_array($result);
        $notifID = $row['notif_id'];
        return $notifID;
    }

    function addNotif($userName,$notifBody){
        $query = "INSERT INTO notification(user_name,notif_body) VALUE('$userName','$notifBody')";
        $result = mysql_query($query);
    }

    function seeNotif($userName,$notifBody){
        $notifID = $this->showNotifID($userName, $notifBody);
        $query = "UPDATE notification SET seen = 'yes' WHERE notif_id = '$notifID'";
    }

    function showUnseenNotif($userName){
        $query = "SELECT * FROM notification WHERE user_name = '$userName' AND seen = 'no'";
        $result = mysql_query($query);
        return $result;
    }

    function getNumberUnseenNotif($userName){
        $query = "SELECT * FROM notification WHERE user_name = '$userName' AND seen = 'no'";
        $result = mysql_query($query);
        $numRow = mysql_num_rows($result);
        return $numRow;
    }
}
?>
